package org.ceteca.explica.core.partners;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;







/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class BankAccountOT extends BaseVO implements Serializable{
	
	

	private static final long serialVersionUID = 1L;
	private long idBankAccount;
	private String description;
	private long idBank;
	private long idBranch;
	private long accountNumber;
	private long controlNumber;
	private PartnerOT partner;
	private Integer version=new Integer(0);

	
	
	public BankAccountOT() {
		super();

		
	}

	public long getIdBankAccount() {
		return idBankAccount;
	}

	public void setIdBankAccount(long idBankAccount) {
		this.idBankAccount = idBankAccount;
	}

	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public long getIdBank() {
		return idBank;
	}
	public void setIdBank(long idBank) {
		this.idBank = idBank;
	}
	public long getIdBranch() {
		return idBranch;
	}
	public void setIdBranch(long idBranch) {
		this.idBranch = idBranch;
	}
	public long getAccountNumber() {
		return accountNumber;
	}
	public void setAccountNumber(long accountNumber) {
		this.accountNumber = accountNumber;
	}
	public long getControlNumber() {
		return controlNumber;
	}
	public void setControlNumber(long controlNumber) {
		this.controlNumber = controlNumber;
	}
	public Integer getVersion() {
		return version;
	}

	
	
	



	@Override
	public boolean equals(Long id) {
		return id != null && this.idBankAccount == id.longValue();
	}

	
	@Override
	public String getEntityId() {

		return InterfacePartners.EXPLICA_ENTITY_BANKACCOUNT_ID;
	}

	@Override
	public long getInternalId() {

		return this.idBankAccount;
	}



	

	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		
		try{
				result.append("\n%%%%%%%%%%%% BEGIN BANK ACCOUNT DETAIL %%%%%%%%%%%%%%");
				result.append("\nID: ");
				result.append(this.idBankAccount);
				result.append("\nDescription: ");
				result.append(this.description);
				if (getPartner()!=null)
					result.append(this.getPartner().toString());
				result.append("\n%%%%%%%%%%%% END BANK ACCOUNT DETAIL%%%%%%%%%%%%%%%%");
			}
			catch (Exception ex) {
				System.out.println("Error formatting Bank Account!");
				ex.printStackTrace();
				return null;
			}
			
			return result.toString();
	}
	@Override
	public String getInternalValue() {
		return this.description;
	}
	public void setVersion(Integer version) {
		this.version = version;
	}
	public PartnerOT getPartner() {
		return partner;
	}
	public void setPartner(PartnerOT partner) {
		this.partner = partner;
	}

	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(this.getIdBank());
	        hcb.append(getAccountNumber());
	        hcb.append(getIdBranch());
	        hcb.append(getControlNumber());

	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final BankAccountOT other = (BankAccountOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getIdBank(), other.getIdBank());
	            eqb.append(getControlNumber(), other.getControlNumber());
	            eqb.append(getAccountNumber(), other.getAccountNumber());
	            eqb.append(getControlNumber(), other.getControlNumber());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }
	
	

}
